package com.tianbo.service.imp;

import com.tianbo.common.ModelAndPage;
import com.tianbo.mapper.TEtlMessageMapper;
import com.tianbo.model.TEtlMessage;
import com.tianbo.model.TEtlMessageExample;
import com.tianbo.service.EtlmessageService;
import com.tianbo.util.dao.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * Created by Mr.Xu on 2017/9/14.
 */
@Service
public class EtlmessageImpl implements EtlmessageService {
    @Autowired
    private TEtlMessageMapper etlMessageMapper;
    public ModelAndPage findEtlMessage(int start, int pagelenth) throws Exception{
        Calendar theCa = Calendar.getInstance();
        theCa.setTime(new Date());
        theCa.add(theCa.DATE, -30);
        Date date = theCa.getTime();
        TEtlMessageExample etlMessageExample=new TEtlMessageExample();
        etlMessageExample.createCriteria().andSntmBetween(date,new Date());
        Page page=new Page(start,pagelenth);
        etlMessageExample.setPage(page);
        int count=etlMessageMapper.countByExample(etlMessageExample);
        page.setCount(count);
        List<TEtlMessage> etlMessageList=etlMessageMapper.selectByExample(etlMessageExample);
        ModelAndPage<TEtlMessage> modelAndPage=new ModelAndPage<TEtlMessage>(etlMessageList,page);
        return modelAndPage;
    }
}
